<?php
require $this->website['path']['action'] . '/admin/islogin.php';

$json = array('status' => 'error', 'msg' => 'error', 'data' => '');

$tit = fn_post('tit');
$tid = fn_post('tid');
$cont = fn_post('cont');
$url = fn_post('url');
$sid = fn_post('sid');
$image = fn_post('image');
$province = fn_post('province');
$city = fn_post('city');
$county = fn_post('county');

if (!$province || !$city || !$county) {
	$json['msg'] = '参数错误,链接区域不能为空';
} elseif (!$tit) {
	$json['msg'] = '参数错误,链接名称不能为空';
} elseif (!is_numeric($tid)) {
	$json['msg'] = '数据错误,链接所属分类错误';
} else {
	$id = $this->website['class']['db']
		->table('link')
		->field('tit', 'tid', 'sid', 'province', 'city', 'county', 'cont', 'url', 'image', 'createtime')
		->value($tit, $tid, $sid, $province, $city, $county, $cont, $url, $image, $_SERVER['REQUEST_TIME'])
		->insert();
	if ($id) {
		$json['status'] = 'ok';
		$json['msg'] = '链接新增成功';
		$json['data'] = $id;
	} else {
		$json['msg'] = '链接新增失败';
		$json['data'] = $this->website['class']['db']->sql;
	}
}

echo json_encode($json);